Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AAS next #1052

Merged
merged 30 commits into from
Sep 12, 2023
Merged

AAS next #1052

merged 30 commits into from
Sep 12, 2023

Conversation

danielpeintner
Copy link
Member

MAY include

  • updates to TD conversion
  • support TD to AAS/AID conversion

@danielpeintner danielpeintner requested a review from relu91 as a code owner August 7, 2023 13:41
@danielpeintner danielpeintner marked this pull request as draft August 7, 2023 13:41
@egekorkan
Copy link
Member

After a talk with @Kaz040 and @danielpeintner, we have realized that TD -> AID will have some limitations at the moment. AID do not support multiple forms per affordance at the moment so we need to be selective. The proposal is for now to do the following:

If a TD has multiple forms, we follow the following implementation steps and give options to the developer:

  1. Take the first form (default behavior)
  2. Give option to pick form based on a certain preference
  • Protocol
  • Type of href: IPv4, IPv6, Domain name
  • Content Type
  • Security

I think that this form picking option can be almost put into a more generic place since I could also think of a WoT consumer needing a logic to pick such a form.

Note: examples AID_v03.json and AID_v03_counter.json are no longer compliant -> skipped for now
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Patch coverage: 85.32% and project coverage change: -0.36% ⚠️

Comparison is base (ef86533) 75.63% compared to head (9de4893) 75.28%.
Report is 42 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1052      +/-   ##
==========================================
- Coverage   75.63%   75.28%   -0.36%     
==========================================
  Files          80       80              
  Lines       15324    16070     +746     
  Branches     1460     1503      +43     
==========================================
+ Hits        11591    12099     +508     
- Misses       3699     3932     +233     
- Partials       34       39       +5     
Files Changed Coverage Δ
...s/td-tools/src/util/asset-interface-description.ts 81.34% <85.32%> (+2.47%) ⬆️

... and 27 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@danielpeintner
Copy link
Member Author

Some more questions w.r.t. alignment between TD and AID arises about title(s) and description(s):

  • AID has the term description but in fact it contains descriptions arrays like [{"language": "en", "text": "Counter"}, {"language": "de", "text": "Zähler"}]
  • AID does not have descriptions ...
  • title uses just string like {"idShort": "title", "valueType": "xs:string", "value": "Count"}
  • ...

--> seems inconsistent

@danielpeintner danielpeintner marked this pull request as ready for review September 7, 2023 13:20
@danielpeintner
Copy link
Member Author

The PR is read for review. It allows for

  • transforming AAS or AID submodel(s) to TD
  • converting TD to AAS or AID submodel

Please have a look @egekorkan @sebastiankb @Kaz040 and others.
Note1: it is a BIG rewrite, hence the diff might not help a lot.
Note2: There are tests but I expect follow-up PRs.

The important API calls are in the following lines.

/**
* Transform AAS in JSON format to a WoT ThingDescription (TD)
*
* @param aas input AAS in JSON format
* @param template TD template with basic desired TD template
* @param submodelRegex allows to filter submodel elements based on regex expression (e.g, "HTTP*") or full text based on idShort (e.g., "InterfaceHTTP")
* @returns transformed TD
*/
public transformAAS2TD(aas: string, template?: string, submodelRegex?: string): string {
const smInformation = this.getSubmodelInformation(aas, submodelRegex);
return this._transform(smInformation, template);
}
/**
* Transform AID submodel definition in JSON format to a WoT ThingDescription (TD)
*
* @param aid input AID submodel in JSON format
* @param template TD template with basic desired TD template
* @param submodelRegex allows to filter submodel elements based on regex expression (e.g, "HTTP*") or full text based on idShort (e.g., "InterfaceHTTP")
* @returns transformed TD
*/
public transformSM2TD(aid: string, template?: string, submodelRegex?: string): string {
const submodel = JSON.parse(aid);
const smInformation: SubmodelInformation = {
actions: new Map<string, Array<AASInteraction>>(),
events: new Map<string, Array<AASInteraction>>(),
properties: new Map<string, Array<AASInteraction>>(),
endpointMetadataArray: [],
thing: new Map<string, Record<string, unknown>>(),
};
this.processSubmodel(smInformation, submodel, submodelRegex);
return this._transform(smInformation, template);
}
/**
* Transform WoT ThingDescription (TD) to AAS in JSON format
*
* @param td input TD
* @param protocols protocol prefixes of interest (e.g., ["http", "coap"]) or optional if all
* @returns transformed AAS in JSON format
*/
public transformTD2AAS(td: string, protocols?: string[]): string {
const submodel = this.transformTD2SM(td, protocols);
const submodelObj = JSON.parse(submodel);
const submodelId = submodelObj.id;
// configuration
const aasName = "SampleAAS";
const aasId = "https://example.com/ids/aas/7474_9002_6022_1115";
const aas = {
assetAdministrationShells: [
{
idShort: aasName,
id: aasId,
assetInformation: {
assetKind: "Type",
},
submodels: [
{
type: "ModelReference",
keys: [
{
type: "Submodel",
value: submodelId,
},
],
},
],
modelType: "AssetAdministrationShell",
},
],
submodels: [submodelObj],
conceptDescriptions: [],
};
return JSON.stringify(aas);
}
/**
* Transform WoT ThingDescription (TD) to AID submodel definition in JSON format
*
* @param td input TD
* @param protocols protocol prefixes of interest (e.g., ["http", "coap"]) or optional if all
* @returns transformed AID submodel definition in JSON format
*/
public transformTD2SM(tdAsString: string, protocols?: string[]): string {
const td: ThingDescription = TDParser.parseTD(tdAsString);
const aidID = td.id ? td.id : "ID" + Math.random();
logInfo("TD " + td.title + " parsed...");
// collect all possible prefixes
if (protocols === undefined || protocols.length === 0) {
protocols = this.getProtocolPrefixes(td);
}
const submdelElements = [];
for (const protocol of protocols) {
// use protocol binding prefix like "http" for name
const submodelElementIdShort = protocol === undefined ? "Interface" : "Interface" + protocol.toUpperCase();
const submdelElement = {
idShort: submodelElementIdShort,
// semanticId needed?
// embeddedDataSpecifications needed?
value: [
{
idShort: "title",
valueType: "xs:string",
value: td.title,
modelType: "Property",
},
// support and other?
this.createEndpointMetadata(td), // EndpointMetadata like base, security and securityDefinitions
this.createInterfaceMetadata(td, protocol), // InterfaceMetadata like properties, actions and events
// externalDescriptor ?
],
modelType: "SubmodelElementCollection",
};
submdelElements.push(submdelElement);
}
const aidObject = {
idShort: "AssetInterfacesDescription",
id: aidID,
kind: "Instance",
// semanticId needed?
description: [
// TODO does this need to be an array or can it simply be a value
{
language: "en",
text: td.title, // TODO should be description, where does title go to? later on in submodel?
},
],
submodelElements: submdelElements,
modelType: "Submodel",
};
return JSON.stringify(aidObject);
}

danielpeintner added a commit to danielpeintner/thingweb.node-wot that referenced this pull request Sep 8, 2023
Note: leave out  asset-interface-description.ts because of eclipse-thingweb#1052
@danielpeintner danielpeintner merged commit 03751a9 into eclipse-thingweb:master Sep 12, 2023
8 checks passed
danielpeintner added a commit that referenced this pull request Sep 22, 2023
…ullChecks (#1077)

* chore: enable eslint/strict-boolean-expressions and strictNullChecks

* fix package examples

* fix package td-tools

Note: leave out  asset-interface-description.ts because of #1052

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* fix: issue issue introduced by commenting

* move eslint settings to td-tools package only

* fix: lint errors for AID

* refactor: revert changes in package "examples"

* refactor: revert "!== undefined" to "!= null"

OR "=== undefined" to "== null"

* refactor: revert some changes proposed by @JKRhb

leads to different results

* fix: wrong conversion

* refactor: missing one undefined change

* fix: add proper boolean check

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* refactor: further simplifications

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* refactor: simplify data.version.model check

---------

Co-authored-by: Jan Romann <[email protected]>
Co-authored-by: Cristiano Aguzzi <[email protected]>
JKRhb added a commit to JKRhb/thingweb.node-wot that referenced this pull request Sep 22, 2023
…ullChecks (eclipse-thingweb#1077)

* chore: enable eslint/strict-boolean-expressions and strictNullChecks

* fix package examples

* fix package td-tools

Note: leave out  asset-interface-description.ts because of eclipse-thingweb#1052

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Jan Romann <[email protected]>

* fix: issue issue introduced by commenting

* move eslint settings to td-tools package only

* fix: lint errors for AID

* refactor: revert changes in package "examples"

* refactor: revert "!== undefined" to "!= null"

OR "=== undefined" to "== null"

* refactor: revert some changes proposed by @JKRhb

leads to different results

* fix: wrong conversion

* refactor: missing one undefined change

* fix: add proper boolean check

* Update packages/td-tools/src/thing-model-helpers.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* Update packages/td-tools/src/util/asset-interface-description.ts

Co-authored-by: Cristiano Aguzzi <[email protected]>

* refactor: further simplifications

* Update packages/td-tools/src/td-parser.ts

Co-authored-by: Jan Romann <[email protected]>

* refactor: simplify data.version.model check

---------

Co-authored-by: Jan Romann <[email protected]>
Co-authored-by: Cristiano Aguzzi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants